﻿using System;
using System.Collections.Generic;
using System.IO;

using System.Text;
using IBatisNet.Common;
using IBatisNet.Common.Utilities;
using IBatisNet.DataAccess;
using NUnit.Framework;
using Wolfut.MirageEE.Core.Service;

namespace Wolfut.MirageEE.Core.Test.DaoTest
{
    [TestFixture]
    public class TestFixtureBase
    {
        protected static string ScriptDirectory = null;
        protected IDaoManager daoManager = null;


        public TestFixtureBase()
        {
            ScriptDirectory = Path.Combine(Path.Combine(Path.Combine(Resources.ApplicationBase, ".."), ".."), "Scripts")+ Path.DirectorySeparatorChar;
	
        }
        [SetUp]
        public void TestInitialize()
        {
            InitializeFramework();
            CreateData();
        }

        private void CreateData()
        {

            try
            {
                daoManager = ServiceConfig.GetInstance().MyDaoManager;
                //foreach (string file in System.IO.Directory.GetFiles(ScriptDirectory))
                //{
                //    InitScript(daoManager.LocalDataSource, Path.Combine(ScriptDirectory, file));

                //}
                //InitScript(daoManager.LocalDataSource, Path.Combine(ScriptDirectory, "Schema.sql"));
                //InitScript(daoManager.LocalDataSource, Path.Combine(ScriptDirectory, "DBUser.sql"));
                //InitScript(daoManager.LocalDataSource, Path.Combine(ScriptDirectory, "DataLoad.sql"));
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
               
            
           
        }

        /// <summary>
        /// Run a sql batch for the datasource.
        /// </summary>
        /// <param name="datasource">The datasource.</param>
        /// <param name="script">The sql batch</param>
        protected static void InitScript(IDataSource datasource, string script)
        {
            ScriptRunner runner = new ScriptRunner();

            runner.RunScript(datasource, script);
        }

        private void InitializeFramework()
        {
           
        }


        [TearDown]
        public void TestCleanUp()
        {
           
        }
    }
}
